﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;

namespace SemestralniPraceY35VAN
{
    class Mayor
    {
        /// <summary>
        /// Properties of the mayor.
        /// </summary>
        private Hashtable properties;

        /// <summary>
        /// 
        /// </summary>
        public string Type { get { if (properties.ContainsKey("type")) return (string)properties["type"]; else return null; } }

        /// <summary>
        /// 
        /// </summary>
        public int Checkins { get { if (properties.ContainsKey("checkins")) return Int16.Parse((string)properties["checkins"]); else return 0; } }

        /// <summary>
        /// 
        /// </summary>
        public User User { get { if (properties.ContainsKey("user")) return (User)properties["user"]; else return null; } }

        /// <summary>
        /// 
        /// </summary>
        public string Message { get { if (properties.ContainsKey("message")) return (string)properties["message"]; else return null; } }

        /// <summary>
        /// Constructs an object representing a mayor.
        /// </summary>
        /// <param name="mayor">XML node with information about the mayor</param>
        public Mayor(XmlNode mayor)
        {
            properties = new Hashtable();

            if (mayor.Name == "mayor")
            {
                for (int i = 0; i < mayor.ChildNodes.Count; i++)
                {
                    switch (mayor.ChildNodes[i].Name)
                    {
                        case "user":
                            properties.Add(mayor.ChildNodes[i].Name, new User(mayor.ChildNodes[i]));
                            break;
                        default:
                            properties.Add(mayor.ChildNodes[i].Name, mayor.ChildNodes[i].InnerText);
                            break;
                    }
                }
            }
            else
            {
                throw new IOException("Not Mayor!");
            }
        }
    }
}
